package palace;

import java.awt.event.KeyEvent;

import festival.game.GameState;
import festival.input.Action;
import festival.input.InputListener;
import festival.player.Player;

public class PalaceFestival {

	private Player[] mPlayers;
	private int mStartingPlayerId;
	private int mCurrentPlayerId;
	private PalaceCard mFestivalCard;
	private int mPalaceSize;
	
	private GameState mGameState;
	
	private GameState mPlayCardsState;
	private GameState mWaitForPlayerState;
	
	public PalaceFestival (Player[] players, int startingPlayerId, PalaceCard festivalCard, int palaceSize) {
		mPlayers = players;
		mStartingPlayerId = startingPlayerId;
		mCurrentPlayerId = startingPlayerId;
		mFestivalCard = festivalCard;
		mPalaceSize = palaceSize;
		
		initGameStates();
		startTurn();
	}
	
	private void startTurn() {
		//TODO
	}
	
	private void passTurn() {
		mCurrentPlayerId++;
		mCurrentPlayerId %= mPlayers.length;
		
		if (mCurrentPlayerId == mStartingPlayerId)
			endPalaceFestival();
	}

	private void endPalaceFestival() {
		// TODO Auto-generated method stub
		
	}

	private void initGameStates() {
		/*
		 * State that allows player to do any of the available moves. If a move is
		 * not allowed, we need to alert the player.
		 */
	    mPlayCardsState = new GameState()
	    .addInputListener(new InputListener(KeyEvent.VK_X, new Action() {
            public void doAction() {
	    	    passTurn();
	    	    changeState(mWaitForPlayerState);
            }
        }));
	    
	    mWaitForPlayerState = new GameState()
	    .addInputListener(new InputListener(KeyEvent.VK_ENTER, new Action() {
            public void doAction() {
	    	    startTurn();
	    	    changeState(mPlayCardsState);
            }
        }));
	}
	
	private void changeState(GameState l) {
	    mGameState = l;
//	    notifyGameStateChanged();
	}

}
